package com.faryangsh.Service;

import com.faryangsh.bean.one.UserOne;
import com.faryangsh.rep.one.UserOneJpaRepository;
import com.faryangsh.rep.one.UserOneRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 杨志远[of2551]
 *         company qianmi.com
 *         Date    2017-07-11
 */
@Service
@Transactional
public class UserService {
    @Autowired
    private UserOneJpaRepository userOneJpaRepository;
    @Autowired
    private UserOneRepository userOneRepository;

    public List<UserOne> findAll()
    {
        return userOneJpaRepository.findAll();
    }

    public List<UserOne> findByName(String name)
    {
       /* List<User> userList1 = userRepositoryOne.findByName1(name);
        List<User> userList2 = userRepositoryOne.findByName2(name);
        List<User> userList3 = userRepositoryOne.findByNameAndAddress(name, "3");
        System.out.println("userList1:" + userList1);
        System.out.println("userList2:" + userList2);
        System.out.println("userList3:" + userList3);*/
        return userOneRepository.findByName(name);
    }

    public void saveUser(UserOne book)
    {
        userOneJpaRepository.save(book);
    }

    public UserOne findOne(long id)
    {
        System.out.println("Cached Pages");
        return userOneJpaRepository.findOne(id);
    }

    public void delete(long id)
    {
        userOneJpaRepository.delete(id);
    }

    public List<UserOne> findByNameLike(String name) {
        return userOneRepository.findByNameIgnoreCaseContaining(name);
    }
}
